package com.uade.business;

public class Paginacion {

	private int pageSize = 10;
    private int pageIndex;
    private int totalItems;
    private Object data;
    
    private int firstItem;
    private int lastItem;
    private int totalPages;
    private int previousPageIndex;
    private int nextPageIndex;
    private boolean hasPreviousPage;
    private boolean hasNextPage;
    private boolean hasData;
    
    public void calcular(){
    	firstItem = getFirstItem();
        lastItem = getLastItem();
        totalPages = getTotalPages();
        previousPageIndex = getPreviousPageIndex();
        nextPageIndex = getNextPageIndex();
        hasPreviousPage = getHasPreviousPage();
        hasNextPage = getHasNextPage();
        hasData = getHasData();
    }
    
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getPageIndex() {
		return pageIndex;
	}
	public void setPageIndex(int pageIndex) {
		this.pageIndex = pageIndex;
	}
	public int getTotalItems() {
		return totalItems;
	}
	public void setTotalItems(int totalItems) {
		this.totalItems = totalItems;
	}
	public Object getData() {
		return data;
	}
	public void setData(Object data) {
		this.data = data;
	}
    
    
	
	public int getFirstItem()
    {
        return pageSize * pageIndex;
    }

    public int getLastItem()
    {
        int i = pageSize*pageIndex + pageSize;
        if (i > totalItems)
            return totalItems;
        return i;
    }

    public int getTotalPages()
    {
        int pags = totalItems/pageSize;
        if ((totalItems % pageSize) == 0)
            pags--;
        return pags;
    }

    public int getPreviousPageIndex()
    {
        return pageIndex - 1;
    }

    public int getNextPageIndex()
    {
        return pageIndex + 1;
    }

    public boolean getHasPreviousPage()
    {
        return pageIndex > 0;
    }

    public boolean getHasNextPage()
    {
        return pageIndex < getTotalPages();
    }

    public boolean getHasData()
    {
        return totalItems > 0;
    }
}
